import 'dart:async';

import 'package:flutter/services.dart';
import 'package:jm_flutter/jm_flutter.dart';

import '../controller/app_controller.dart';

class PlatformChannelService {
  static const tag = "PlatformChannelService";

  static const _methodChannel =
      MethodChannel('flutter.io.jml.JmFlutterDemo/PlatformChannel');

  static PlatformChannelService? _instance;

  AppController? get _appController => currentApp;

  PlatformChannelService._() {
    _methodChannel.setMethodCallHandler((call) async {
      logd(tag, "${call.method}:${call.arguments}");
    });
  }

  factory PlatformChannelService() {
    _instance ??= PlatformChannelService._();
    return _instance!;
  }

  void setData(String data) {
    _methodChannel.invokeMethod("setData", data);
  }

  Future<String?> getData() {
    return _methodChannel.invokeMethod("getData");
  }
}
